home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / TAIL.ASM < prev    next >
Assembly Source File  |  1991-03-25  |  10KB  |  383 lines

  1. ;   PC/FTP Packet Driver source, conforming to version 1.05 of the spec
  2. ;   Russell Nelson, Clarkson University.  July 20, 1988
  3. ;   Updated to version 1.08 Feb. 17, 1989.
  4. ;   Copyright 1988,1989,1990,1991 Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     extrn    phd_dioa: byte
  25.     extrn    phd_environ: word
  26.     extrn    flagbyte: byte
  27.  
  28.     include    printnum.asm
  29.     include    decout.asm
  30.     include    digout.asm
  31.     include    chrout.asm
  32.  
  33. end_tail_1    label    byte        ; end of the delayed init driver
  34.  
  35. ;usage_msg is of the form "usage: driver [-d -n] <packet_int_no> <args>"
  36.     extrn    usage_msg: byte
  37.  
  38. ;copyright_msg is of the form:
  39. ;"Packet driver for the foobar",CR,LF
  40. ;"Portions Copyright 19xx, J. Random Hacker".
  41.     extrn    copyright_msg: byte
  42.  
  43. copyleft_msg    label    byte
  44.  db "Packet driver skeleton copyright 1988-91, Russell Nelson.",CR,LF
  45.  db "This program is free software; see the file COPYING for details.",CR,LF
  46.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  47.  db CR,LF
  48. crlf_msg    db    CR,LF,'$'
  49.  
  50. no_resident_msg    label    byte
  51.  db CR,LF,"*** Packet driver failed to initialize the board ***",CR,LF,'$'
  52.  
  53. ;parse_args should parse the arguments.
  54. ;called with ds:si -> immediately after the packet_int_no.
  55.     extrn    parse_args: near
  56.  
  57. ;print_parameters should print the arguments.
  58.     extrn    print_parameters: near
  59.  
  60.     extrn    our_isr: near, their_isr: dword
  61.     extrn    packet_int_no: byte
  62.     extrn    is_at: byte, sys_features: byte
  63.     extrn    int_no: byte
  64.     extrn    driver_class: byte
  65.  
  66. location_msg    db    "Packet driver is at segment ",'$'
  67.  
  68. packet_int_no_name    db    "Packet interrupt number ",'$'
  69. eaddr_msg    db    "My Ethernet address is ",'$'
  70. aaddr_msg    db    "My ARCnet address is ",'$'
  71.  
  72. already_msg    db    CR,LF,"There is already a packet driver at ",'$'
  73. int_msg        db    CR,LF
  74.         db    "Error: <int_no> should be between 0 and "
  75. int_msg_num    label    word
  76.         db    "15 inclusive", '$'
  77.  
  78. our_address    db    EADDR_LEN dup(?)
  79.     public    etopen_diagn
  80. etopen_diagn    db    0        ; errorlevel from etopen if set
  81.  
  82. ;etopen should initialize the device.  If it needs to give an error, it
  83. ;can issue the error message and quit to dos.
  84.     extrn    etopen: near
  85.  
  86. ;get the address of the interface.
  87. ;enter with es:di -> place to get the address, cx = size of address buffer.
  88. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  89.     extrn    get_address: near
  90.  
  91. already_error:
  92.     mov    dx,offset already_msg
  93.     mov    di,offset packet_int_no
  94.     call    print_number
  95.     mov    ax,4c05h        ; give errorlevel 5
  96.     int    21h
  97.  
  98. usage_error:
  99.     mov    dx,offset usage_msg
  100.     public    error
  101. error:
  102.     mov    ah,9
  103.     int    21h
  104.     mov    ax,4c0ah        ; give errorlevel 10
  105.     int    21h
  106.  
  107.     include    timeout.asm
  108.  
  109.     public    start_1
  110. start_1:
  111.     cld
  112.  
  113.     mov    dx,offset copyright_msg
  114.     mov    ah,9
  115.     int    21h
  116.  
  117.     mov    dx,offset copyleft_msg
  118.     mov    ah,9
  119.     int    21h
  120.  
  121. ;
  122. ; Get the feature byte (if reliable) so we can know if it is a microchannel
  123. ; computer and how many interrupts there are.
  124. ;
  125.     mov    ah,0c0h
  126.     int    15h            ; es:bx <- sys features block
  127.     jc    look_in_ROM        ; error, must use rom.
  128.     or    ah,ah
  129.     jnz    look_in_ROM
  130.     mov    dx,es:[bx]        ; # of feature bytes
  131.     cmp    dx,4            ; do we have the feature byte we want?
  132.     jae    got_features        ;yes.
  133. look_in_ROM:
  134.     mov    dx,0f000h        ;ROM segment
  135.     mov    es,dx
  136.     cmp    byte ptr es:[0fffeh],0fch;is this an AT?
  137.     jne    identified        ;no.
  138.     or    sys_features,TWO_8259    ; ATs have 2nd 8259
  139.     jmp    identified        ; assume no microchannel
  140. got_features:
  141.     mov    ah,es:[bx+2]        ; model byte
  142.     cmp    ah,0fch
  143.     je    at_ps2
  144.     ja    identified        ; FD, FE and FF are not ATs
  145.     cmp    ah,0f8h
  146.     je    at_ps2
  147.     ja    identified        ; F9, FA and FB are not ATs
  148.     cmp    ah,09ah
  149.     jbe    identified        ; old non-AT Compacs go here
  150. at_ps2:                    ; 9B - F8 and FC are assumed to
  151.     mov    ah,es:[bx+5]        ;   have reliable feature byte
  152.     mov    sys_features,ah
  153. identified:
  154.  
  155.     mov    si,offset phd_dioa+1
  156.     call    skip_blanks        ;end of line?
  157.     cmp    al,CR
  158.     je    usage_error_j_1
  159.  
  160. ;print the location we were loaded at.
  161.     mov    dx,offset location_msg
  162.     mov    ah,9
  163.     int    21h
  164.  
  165.     mov    ax,cs            ;print cs as a word.
  166.     call    wordout
  167.  
  168.     mov    dx,offset crlf_msg
  169.     mov    ah,9
  170.     int    21h
  171.  
  172. chk_options:
  173.     call    skip_blanks
  174.     cmp    al,'-'            ; any options?
  175.     jne    no_more_opt
  176.     inc    si            ; skip past option char
  177.     lodsb                ; read next char
  178.     or    al,20h            ; convert to lower case
  179.     cmp    al,'d'
  180.     jne    not_d_opt
  181.     or    flagbyte,D_OPTION
  182.     jmp    chk_options
  183. not_d_opt:
  184.     cmp    al,'n'
  185.     jne    not_n_opt
  186.     or    flagbyte,N_OPTION
  187.     jmp    chk_options
  188. not_n_opt:
  189.     cmp    al,'w'
  190.     jne    not_w_opt
  191.     or    flagbyte,W_OPTION
  192.     jmp    chk_options
  193. not_w_opt:
  194. usage_error_j_1:
  195.     jmp    usage_error
  196. no_more_opt:
  197.  
  198.     mov    di,offset packet_int_no    ;parse the packet interrupt number
  199.     mov    bx,offset packet_int_no_name
  200.     call    get_number        ;  for them.
  201.  
  202.     call    parse_args
  203.     jc    usage_error_j_1
  204.  
  205.     call    skip_blanks        ;end of line?
  206.     cmp    al,CR
  207.     jne    usage_error_j_1
  208.  
  209.     call    verify_packet_int
  210.     jnc    packet_int_ok
  211.     jmp    error
  212. packet_int_ok:
  213.     jne    packet_int_unused
  214.     jmp    already_error        ;give an error if there's one there.
  215. packet_int_unused:
  216.  
  217. ;
  218. ; Verify that the interrupt number they gave is valid.
  219. ;
  220.     cmp    int_no,15        ;can't possibly be > 15.
  221.     ja    int_bad
  222.     test    sys_features,TWO_8259    ; 2nd 8259 ?
  223.     jnz    int_ok            ;yes, no need to check for <= 7.
  224.     mov    int_msg_num,'7'+' '*256    ;correct the error message, just in case.
  225.     cmp    int_no,7        ;make sure that the packet interrupt
  226.     jbe    int_ok            ;  number is in range.
  227. int_bad:
  228.     mov    dx,offset int_msg
  229.     jmp    error
  230. int_ok:
  231.  
  232. ;
  233. ; Map IRQ 2 to IRQ 9 if needed.
  234. ;
  235.     test    sys_features,TWO_8259    ; 2nd 8259 ?
  236.     je    no_mapping_needed    ;no, no mapping needed
  237.     cmp    int_no,2        ;map IRQ 2 to IRQ 9.
  238.     jne    no_mapping_needed
  239.     mov    int_no,9
  240. no_mapping_needed:
  241.  
  242. ; If they chose the -d option, don't call etopen when we are loaded,
  243. ; but when we are called for the first time
  244. ;
  245. ; Save part of the tail, needed by delayed etopen
  246.     test    flagbyte,D_OPTION
  247.     jnz    delayed_open
  248.     call    etopen            ;init the driver.  If any errors,
  249.                     ;this routine returns cy.
  250.     jnc    yes_resident
  251.     jmp    no_resident
  252. delayed_open:
  253.     mov    dx,offset end_tail_1    ; save first part of tail
  254.     push    dx            ;remember where they want to end.
  255.     call    take_packet_int
  256.     jmp    delayed_open_1
  257.  
  258. yes_resident:
  259.     push    dx            ;remember where they want to end.
  260.  
  261.     call    print_parameters    ;echo our parameters.
  262.     or    flagbyte,CALLED_ETOPEN
  263.  
  264.     call    take_packet_int
  265.  
  266.     cmp    driver_class,1        ;Ethernet?
  267.     jne    print_addr_2        ;no, don't print what we don't have.
  268.  
  269.     push    ds
  270.     pop    es
  271.     mov    di,offset our_address
  272.     mov    cx,EADDR_LEN
  273.     call    get_address
  274.  
  275.     mov    dx,offset eaddr_msg
  276.     mov    ah,9
  277.     int    21h
  278.  
  279.     mov    si,offset our_address
  280.     call    print_ether_addr
  281.  
  282.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  283.     mov    ah,9
  284.     int    21h
  285.  
  286. print_addr_2:
  287.  
  288.     cmp    driver_class,8        ;ARCnet?
  289.     jne    print_addr_3        ;no, don't print what we don't have.
  290.  
  291.     push    ds
  292.     pop    es
  293.     mov    di,offset our_address
  294.     mov    cx,ARCADDR_LEN
  295.     call    get_address
  296.  
  297.     mov    dx,offset aaddr_msg
  298.     mov    ah,9
  299.     int    21h
  300.  
  301.     mov    al,our_address
  302.     mov    cl,' '            ;Don't eliminate leading zeroes.
  303.     call    byteout
  304.  
  305.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  306.     mov    ah,9
  307.     int    21h
  308.  
  309. print_addr_3:
  310. delayed_open_1:
  311.  
  312.     mov    ah,49h            ;free our environment, because
  313.     mov    es,phd_environ        ;  we won't need it.
  314.     int    21h
  315.  
  316.     mov    bx,1            ;get the stdout handle.
  317.     mov    ah,3eh            ;close it in case they redirected it.
  318.     int    21h
  319.  
  320.     pop    dx            ;get their ending address.
  321.     add    dx,0fh            ;round up to next highest paragraph.
  322.     mov    cl,4
  323.     shr    dx,cl
  324.     mov    ah,31h            ;terminate, stay resident.
  325.     mov    al,etopen_diagn        ; errorlevel (0 - 9, just diagnostics)
  326.     int    21h
  327.  
  328. no_resident:
  329.     mov    dx,offset no_resident_msg
  330.     mov    ah,9
  331.     int    21h
  332.  
  333.     mov    ax,4c00h + 32        ; give errorlevel 32
  334.     cmp    al,etopen_diagn
  335.     ja    no_et_diagn        ; etopen gave specific reason?
  336.     mov    al,etopen_diagn        ; yes, use that for error level
  337. no_et_diagn:
  338.     int    21h
  339.  
  340. ;             Suggested errorlevels:
  341. ;
  342. ; _____________________  0 = normal
  343. ;              1 = unsuitable memory address given; corrected
  344. ; In most cases every-     2 = unsuitable IRQ level given; corrected
  345. ; thing should work as     3 = unsuitable DMA channel given; corrected
  346. ; expected for lev 1-5     4 = unsuitable IO addr given; corrected (only 1 card)
  347. ; _____________________     5 = packet driver for this int # already loaded
  348. ; External errors, when    20 = general cable failure (but pkt driver is loaded)
  349. ; corrected normal    21 = network cable is open             -"-
  350. ; operation starts    22 = network cable is shorted          -"-
  351. ; _____________________ 23 = 
  352. ; Packet driver not    30 = usage message
  353. ; loaded. A new load    31 = arguments out of range
  354. ; attempt must be done    32 = unspecified device initialization error
  355. ;            33 = 
  356. ;            34 = suggested memory already occupied
  357. ;            35 = suggested IRQ already occupied
  358. ;            36 = suggested DMA channel already occupied
  359. ;            37 = could not find the network card at this IO address
  360.  
  361.  
  362. take_packet_int:
  363.     mov    ah,35h            ;remember their packet interrupt.
  364.     mov    al,packet_int_no
  365.     int    21h
  366.     mov    their_isr.offs,bx
  367.     mov    their_isr.segm,es
  368.  
  369.     mov    ah,25h            ;install our packet interrupt
  370.     mov    dx,offset our_isr
  371.     int    21h
  372.     ret
  373.  
  374.     include    verifypi.asm
  375.     include    getnum.asm
  376.     include    getdig.asm
  377.     include    skipblk.asm
  378.     include    printea.asm
  379.  
  380. code    ends
  381.  
  382.     end
  383.